<!DOCTYPE html>
<html>

	<head>
		<meta charset="utf-8">
		<meta http-equiv="X-UA-Compatible" content="IE=edge">
		<title>魏远商城</title>
		<meta name="viewport" content="initial-scale=1, maximum-scale=1">
		<link rel="shortcut icon" href="/favicon.ico">
		<meta name="apple-mobile-web-app-capable" content="yes">
		<meta name="apple-mobile-web-app-status-bar-style" content="black">
		<link rel="stylesheet" href="css/style.css" />
		<style type="text/css">
			.mui-toast-container {
				text-align: center;
				position: fixed;
				z-index: 9999;
				bottom: 50px;
				width: 100%;
				-webkit-transition: opacity .8s;
				transition: opacity .8s;
				opacity: 1
			}
			
			.mui-toast-container {
				display: none
			}
		</style>
	</head>

	<body style="background: #eaeef1;">
		<div class="login-head">
			<img src="img/login.png" alt="" height="50%" />
		</div>
		<div class="login-content">
			<input type="text" class="phonenumber" maxlength="11" placeholder="手机号码登录" />
			<input type="password" maxlength="30" class="password" placeholder="请输入6-30位数字/英文的密码" />
			<p class="forget">
				<span class="forget-password">忘记密码</span>
				<span class="register">注册</span>
			</p>
			<div class="common" style="font-size: 1rem;">登录</div>
			<div class="mui-toast-container" id="mui-toast-container">
				<div class="mui-toast-message">登录成功</div>
			</div>
			<!--<div class="company">企业用户登录</div>-->
		</div>
		<script src="js/jquery-3.1.1.min.js" type="text/javascript" charset="utf-8"></script>
		<script src="js/mui.min.js" type="text/javascript" charset="utf-8"></script>
		<script src="js/url.js" type="text/javascript" charset="utf-8"></script>
		<script type="text/javascript">
			var mima = /^[A-Za-z0-9]+$/;
			var hm = /^1[34578]\d{9}$/;
			//		普通用户登录
			function pd(){
				$('#mui-toast-container').css('display', 'inline-block')
//					$('.mui-toast-message').html('请检查您的登录信息');
				setTimeout(function(){
					$('#mui-toast-container').css('display', 'none')
				}, 1000)
			}
			$('.common').on('tap', function() {
				var phone = $('.phonenumber').val();
				var password = $('.password').val();
				if(phone == '') {
					pd();
					$('.mui-toast-message').html('手机号码不能为空，请重新输入');
//					mui.toast('手机号码不能为空，请重新输入');
				}else if(phone.length<11){
					pd();
					$('.mui-toast-message').html('请输入不小于11位的手机号码');
//					mui.toast('请输入不小于11位的手机号码')
				} else if(!hm.test(phone)){
					pd();
					$('.mui-toast-message').html('手机号码不正确，请重新输入');
//					mui.toast('手机号码不正确，请重新输入')
				} else if(password == '') {
					pd();
					$('.mui-toast-message').html('密码不能为空，请重新输入');
//					mui.toast('密码不能为空，请重新输入');
				} else if(password.length < 6){
					pd();
					$('.mui-toast-message').html('请输入不小于6位的密码');
//					mui.toast('请输入不小于6位的密码')
				}else if(!mima.test(password)){
					pd();
					$('.mui-toast-message').html('请输入6-30位数字/英文的密码');
//					mui.toast('请输入6-30位数字/英文的密码')
				}else { //			普通用户登录接口
					login();
				}
				
				function login() {
					$.ajax({
						type: 'post',
						url: ur + '/mobilemember/frontmember/dologin',
						dataType: 'json',
						data: {
							"memberVO.loginName": $('.phonenumber').val(),
							"memberVO.password": $('.password').val(),
						},
						success: function(data) {
							console.log(JSON.stringify(data) + '>>>>>')
							var panduan = data.result.meta.code;
							if(panduan == '200') {
								if(data.result.data.isAdmin == 1) {
									localStorage.isAdmin = data.result.data.isAdmin;
								} else if(data.result.data.isAdmin == 2) {
									localStorage.priseId = data.result.data.enterpriseId;
									localStorage.isAdmin = data.result.data.isAdmin;
								}
								localStorage.token = data.result.data.token;
								console.log(localStorage.token + '可以用的token');
								localStorage.phone = $('.phonenumber').val();
								pd();
								$('.mui-toast-message').html('登录成功,欢迎来到魏远商城');
								mui.back();
							} else if(panduan == '110') {
								pd();
								$('.mui-toast-message').html('系统繁忙，请稍后');
								return;
							} else if(panduan == '308') {
								pd()
								$('.mui-toast-message').html('请检查您的账号或密码');
								return;
							} else {
								pd();
								$('.mui-toast-message').html('请检查您的登录信息');
								return;
							}
						},
						error: function(e) {
							pd();
							$('.mui-toast-message').html('系统繁忙，请稍后再试');
							console.log(e+'登录错误')
						}
					});
				}
			})

			//		忘记密码
			$('.forget-password').on('tap', function() {
				mui.openWindow({
					url: 'forget-password.html',
					id: 'forget-password',
					show: 'pop-in'
				})
			})
			//		注册
			$('.register').on('tap', function() {
				mui.openWindow({
					url: 'register.html',
					id: 'register',
					show: 'pop-in'
				})
			})
		</script>
	</body>

</html>